package com.ruoyi.web.controller.frontierCommand;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.frontierCommand.bo.TCryHelpAddBo;
import com.ruoyi.system.frontierCommand.bo.TCryHelpEditBo;
import com.ruoyi.system.frontierCommand.bo.TCryHelpQueryBo;
import com.ruoyi.system.frontierCommand.service.ITCryHelpService;
import com.ruoyi.system.frontierCommand.vo.TCryHelpVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 求救信息Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "求救信息控制器", tags = {"求救信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/frontierCommand/help")
public class TCryHelpController extends BaseController {

    private final ITCryHelpService iTCryHelpService;

    /**
     * 查询求救信息列表
     */
    @ApiOperation("查询求救信息列表")
//    @PreAuthorize("@ss.hasPermi('frontierCommand:help:list')")
    @GetMapping("/list")
    public TableDataInfo<TCryHelpVo> list(TCryHelpQueryBo bo) {
        startPage();
        List<TCryHelpVo> list = iTCryHelpService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出求救信息列表
     */
    @ApiOperation("导出求救信息列表")
    @PreAuthorize("@ss.hasPermi('frontierCommand:help:export')")
    @Log(title = "求救信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TCryHelpVo> export(TCryHelpQueryBo bo) {
        startPage();
        List<TCryHelpVo> list = iTCryHelpService.queryList(bo);
        ExcelUtil<TCryHelpVo> util = new ExcelUtil<TCryHelpVo>(TCryHelpVo.class);
        return util.exportExcel(list, "求救信息");
    }

    /**
     * 获取求救信息详细信息
     */
    @ApiOperation("获取求救信息详细信息")
    @PreAuthorize("@ss.hasPermi('frontierCommand:help:query')")
    @GetMapping("/{id}")
    public AjaxResult<TCryHelpVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTCryHelpService.queryById(id));
    }

    /**
     * 新增求救信息
     */
    @ApiOperation("新增求救信息")
//    @PreAuthorize("@ss.hasPermi('frontierCommand:help:add')")
    @Log(title = "求救信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TCryHelpAddBo bo) {
        return toAjax(iTCryHelpService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改求救信息
     */
    @ApiOperation("修改求救信息")
    @PreAuthorize("@ss.hasPermi('frontierCommand:help:edit')")
    @Log(title = "求救信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TCryHelpEditBo bo) {
        return toAjax(iTCryHelpService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除求救信息
     */
    @ApiOperation("删除求救信息")
    @PreAuthorize("@ss.hasPermi('frontierCommand:help:remove')")
    @Log(title = "求救信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTCryHelpService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
